package com.hzqy.service.hotel;

import com.hzqy.persistence.dao.hotel.HotelUserNeedsDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.HotelUserNeedsVo;
import com.hzqy.web.vo.HotelUserNeedsVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HotelUserNeedsServiceBean extends GenericServiceBean<HotelUserNeedsVo, HotelUserNeedsDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private HotelUserNeedsDao hotelUserNeedsDao;
	@Override
	public HotelUserNeedsDao getEntityDao() {
		return hotelUserNeedsDao;
	}
	
	/**
	 * 根据id查询用户需求详情
	 */
	public HotelUserNeedsVo selectHotelUserNeedsVo(String f_hsn_id) {
		return hotelUserNeedsDao.selectHotelUserNeedsVo(f_hsn_id);
	}
	
	/**
	 * 	用户需求列表获取
	 * @param curPage
	 * @param pageSize
	 * @return
	 */
	public Map<String,Object> selectHotelUserNeedsList(HotelUserNeedsVo hotelUserNeedsVo, int curPage,
			int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = hotelUserNeedsDao.selectHotelUserNeedsCount(hotelUserNeedsVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("startTime", hotelUserNeedsVo.getStartTime());
			map.put("endTime", hotelUserNeedsVo.getEndTime());
			map.put("serverid", hotelUserNeedsVo.getServerid());
			map.put("roonNum", hotelUserNeedsVo.getRoonNum());
			map.put("f_hsn_orgId", hotelUserNeedsVo.getF_hsn_orgId());
			map.put("type", hotelUserNeedsVo.getType());
			map.put("status", hotelUserNeedsVo.getStatus());
			map.put("star", hotelUserNeedsVo.getStar());
			map.put("f_hsn_printStatus", hotelUserNeedsVo.getF_hsn_printStatus());
			List<HotelUserNeedsVo> results = hotelUserNeedsDao.selectHotelUserNeedsList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<HotelUserNeedsVo>());
		}
		return map;
	}
	

	/**
	 * 删除用户需求
	 */
	public Map<String,Object> deleteHotelUserNeedsVo(String f_hsn_id) {
        Map<String,Object> resultMap = new HashMap<String,Object>();
        int flag = hotelUserNeedsDao.deleteHotelUserNeedsVo(f_hsn_id);
        resultMap.put("resultTitle", "删除结果");
        if(flag>0) {
            resultMap.put("success", true);
            resultMap.put("result","删除成功!");
        } else {
            resultMap.put("success", false);
            resultMap.put("result","删除失败!");
        }
		return resultMap;
	}
	/**
	 * 增加用户需求
	 * @param hotelUserNeedsVo
	 * @return
	 */
	public Map<String,Object> insertHotelUserNeedsVo(HotelUserNeedsVo hotelUserNeedsVo) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(hotelUserNeedsVo==null) {
			flag = -1;
		}
		if(flag ==0) {
				int f_hsn_id =hotelUserNeedsDao.insertHotelUserNeedsVo(hotelUserNeedsVo);
				resultMap.put("success", true);
				resultMap.put("result","新增用户需求成功!");
				resultMap.put("f_hsn_id",f_hsn_id);
		}else{
			resultMap.put("success", false);
			resultMap.put("result","新增用户需求失败!");
		}
		return resultMap;
	}
	/**
	 * 修改用户需求
	 * @param hotelUserNeedsVo
	 * @return
	 */
	public Map<String,Object> updateHotelUserNeedsVo(HotelUserNeedsVo hotelUserNeedsVo) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(hotelUserNeedsVo==null) {
			flag = -1;
		}
		if(flag ==0) {
			hotelUserNeedsDao.updateHotelUserNeedsVo(hotelUserNeedsVo);
			resultMap.put("success", true);
			resultMap.put("result","修改用户需求成功!");
		}else{
			resultMap.put("success", false);
			resultMap.put("result","修改用户需求失败!");
		}
		return resultMap;
	}
	/**
	 * 修改需求状态
	 * @param f_hsn_id
	 * @return
	 */
	public Map<String,Object> updateHotelUserNeedsVoStatus(String f_hsn_id,String f_hsn_status) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(f_hsn_id==null||f_hsn_status==null) flag = -1;
		if(flag ==0) {
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("f_hsn_id",f_hsn_id);
            map.put("f_hsn_status",f_hsn_status);
			hotelUserNeedsDao.updateHotelUserNeedsVoStatus(map);
			resultMap.put("success", true);
			resultMap.put("result","修改需求状态成功!");
		}else{
			resultMap.put("success", false);
			resultMap.put("result","修改需求状态失败!");
		}
		return resultMap;
	}
	/**
	 * 评价
	 * @param f_hsn_id
	 * @return
	 */
	public Map<String,Object> updateHotelUserNeedsVoEvaluate(String f_hsn_id,String f_hsn_evaluate,String f_hsn_star) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(f_hsn_id==null||f_hsn_star==null||!f_hsn_star.matches("^\\d+$")) flag = -1;
		if(flag ==0) {
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("f_hsn_id",f_hsn_id);
            map.put("f_hsn_evaluate",f_hsn_evaluate);
            map.put("f_hsn_star",f_hsn_star);
			hotelUserNeedsDao.updateHotelUserNeedsVoEvaluate(map);
			resultMap.put("success", true);
			resultMap.put("result","评价成功!");
		}else{
			resultMap.put("success", false);
			resultMap.put("result","评价失败!");
		}
		return resultMap;
	}
}
